package com.googlecode.battleofendor.synchroniation.messages;

import java.io.Serializable;

import com.googlecode.battleofendor.synchroniation.ClientPlayer;
import com.googlecode.battleofendor.synchroniation.HostPlayer;

public class Ping implements Serializable {

	private static final long serialVersionUID = 442412267294885443L;
	
	private static long count = 0;
	
	private long sendTime;
	
	private long recievedTime;
	
	public final long ID;
	
	public Ping() {
		ID = count++;
	}
	
	public void ping(HostPlayer host) {
		sendTime = host.currentTimeMillis();
	}
	
	public void pong(ClientPlayer client) {
		recievedTime = client.currentTimeMillis();
	}
	
	public Timedelta back(HostPlayer host) {
		long difference = host.currentTimeMillis() - sendTime;
		long to = difference / 2;
		return new Timedelta((sendTime + to) - recievedTime);
	}
}
